/**
 * Given a sorted linked list, delete all duplicates such that each element appear only once.
 * For example,
 * Given 1->1->2, return 1->2.
 * Given 1->1->2->3->3, return 1->2->3.
 */

 /**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* deleteDuplicates(struct ListNode* head) {
    struct ListNode * firstPtr;
    struct ListNode * secondPtr;
    if (head == 0 || head->next == 0) return head;
    firstPtr = head;
    secondPtr = head->next;
    while (secondPtr->next) {
        if (firstPtr->val != secondPtr->val) {
            firstPtr = firstPtr->next;
            secondPtr = secondPtr->next;
        }
        else {
            if (secondPtr->next->val == firstPtr->val)
                secondPtr = secondPtr->next;
            else {
                firstPtr->next = secondPtr->next;
                secondPtr = secondPtr->next;
            }
        }
    }
    if (secondPtr->val == firstPtr->val) firstPtr->next = 0;
    return head;
}